﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;
using WmsApp.WmsService;

namespace WmsApp.Report
{
    public class ReportOutputOutStoreBill : IReportOutput
    {
        public string ReportID = "出库单";
        #region IReportOutput Members

        public virtual void ShowReport(string key)
        {
            //var list = new List<WmsService.ReportParameter>();
            //var p = new ReportParameter { Condition = String.Format(" and BillID ='{0}'", key), DbTableName = "OutStoreBill" };
            //list.Add(p);
            //p = new ReportParameter { Condition = String.Format(" and BillID ='{0}'", key), DbTableName = "OutStoreBillDtl" };
            //list.Add(p);
            //ReportFactory.ShowReport(ReportID,list);

            var list = new List<WmsService.ReportParameter>();
            var p = new ReportParameter { Condition = String.Format(" and BillID ='{0}'", key), DbTableName = "OutStoreBill" };
            list.Add(p);
            p = new ReportParameter { Condition = String.Format(" and BillID ='{0}'", key), DbTableName = "OutStoreBillDtl" };
            list.Add(p);
            //ReportFactory.ShowReport(ReportID,list);
            try
            {
                DataSet dataSet = Factory.WmsServiceFactory.GetServiceClient().GetDataSet(ReportID, list);
                foreach (var rp in list)
                {
                    if (dataSet.Tables[rp.DbTableName].Rows.Count == 0)
                    {
                        Exceptions.ExceptionHandler.ShowException(String.Format("数据表行数为0，表名：{0}，条件：{1}", rp.DbTableName, rp.Condition));
                        return;
                    }
                }

                dataSet.Tables["OutStoreBillDtl"].DefaultView.Sort = "Idx ASC";

                IXtraReport report = new ReportFile.XtraReportOutStoreBill
                {
                    DataTableMain = dataSet.Tables["OutStoreBill"],
                    DataTableDetail = dataSet.Tables["OutStoreBillDtl"]
                };
                report.ShowPreviewDialog();
            }
            catch (Exception ex)
            {
                Exceptions.ExceptionHandler.ShowException(ex);
            }
        }

        #endregion
    }
}
